package codetop.dp;


import org.junit.Test;

public class Code005 {
    @Test
    public void test(){
        String s="bb";
        System.out.println(longestPalindrome(s));
    }
    public String longestPalindrome(String s) {
        if (s.length()==0)return "";
        int max=0;
        int arr[]=new int[3];
        String ans=s.charAt(0)+"";
        for (int i = 0; i < s.length(); i++) {
            int temp=1;
            while (i-temp>=0&&i+temp<s.length()-1){
                if (s.charAt(i-temp)==s.charAt(i+temp)){
                    int len=2*temp+1;
                    if (max<len){
                        max=len;
                        ans=s.substring(i-temp,i+temp+1);
                    }
                    temp++;
                }
                else break;
            }
            temp=1;
            while (i-temp+1>=0&&i+temp<s.length()-1){
                if (s.charAt(i-temp+1)==s.charAt(i+temp)){
                    int len=2*temp;
                    if (max<len){
                        max=len;
                        ans=s.substring(i-temp+1,i+temp+1);
                    }
                    temp++;
                }
                else break;
            }
        }
        return ans;
    }
}
